<script setup lang="ts">
	import { onLaunch } from '@dcloudio/uni-app'
  import {getLoginWeixinCode} from "@/utils/function";
  import {subMessageTemplateList, wxLogin} from "@/common/api";

  // 创建全局登录Promise
  let resolveLogin: Function;
  uni.$appLogin = new Promise((resolve) => {
    resolveLogin = resolve;
  });

	onLaunch(async() => {
		uni.setInnerAudioOption({
			obeyMuteSwitch: false
		});
    // 检查本地token
    const token = uni.getStorageSync('TOKEN');
    
    // 使用模拟数据替代实际API调用
    setTimeout(() => {
      // 模拟登录成功
      if (!token) {
        // 模拟存储token
        uni.setStorageSync('TOKEN', 'mock_token_12345');
        console.log('模拟登录成功，已设置模拟TOKEN');
      }
      resolveLogin(true); // 直接resolve登录成功
    }, 300);
    
    // 模拟订阅消息模板数据
    const mockTemplates = [
       'VtIYKyVS8vYVIyVtVSIyVtYKVSIyVtVS',
       'VtIYKyVS8vYVIyVtVSIyVtYKVSIyVtV2'
      ]
    
    // 使用模拟模板数据
    const templates = mockTemplates;
    uni.setStorageSync('subMessageTemplateList',templates);
	})
  const _wxLogin = async(code:string) =>{
    try {
      let data = await wxLogin({code});
      uni.hideLoading();
      uni.setStorageSync('TOKEN',data.token);
      return data;
    } catch(err){
      throw err;
    }
  }
</script>
<style lang="scss">
	@import '@/uni_modules/tuniaoui-vue3/index.css';
	@import '@/libs/css/animate.min.css';

	page {
		//background: #E5EEFF;
	}

	.icon_img {
		>image {
			width: 100%;
			height: 100%;
		}
	}
</style>